package com.twu.biblioteca.dispatcher;

import com.twu.biblioteca.constant.BibliotecaConstans;
import com.twu.biblioteca.model.BibliotecaUser;

public class BibliotecaCommandResolver {
    public static boolean isListCommand(String command) {
        return BibliotecaConstans.LIST_COMMAND.equalsIgnoreCase(command.trim());
    }

    public static boolean isCheckoutCommand(String command) {
        String[] subCommands = command.split(" ");
        return subCommands.length > 1 && BibliotecaConstans.CHECKOUT_COMMAND.equalsIgnoreCase(subCommands[0]);
    }

    public static boolean isReturnCommand(String command) {
        String[] subCommands = command.split(" ");
        return subCommands.length > 1 && BibliotecaConstans.RETURN_COMMAND.equalsIgnoreCase(subCommands[0]);
    }

    public static boolean isHelpCommand(String command) {
        return BibliotecaConstans.HELP_COMMAND.equalsIgnoreCase(command.trim());
    }

    public static String resolveCheckoutBook(String command) {
        return command.substring(BibliotecaConstans.CHECKOUT_COMMAND.length()).trim();
    }

    public static String resolveReturnBook(String command) {
        return command.substring(BibliotecaConstans.RETURN_COMMAND.length()).trim();
    }

    public static boolean isAddCommand(String command) {
        String[] subCommands = command.split(" ");
        return subCommands.length > 1 && BibliotecaConstans.ADD_COMMAND.equalsIgnoreCase(subCommands[0]);
    }

    public static String resolveAddBook(String command) {
        return command.substring(BibliotecaConstans.ADD_COMMAND.length()).trim();
    }

    public static boolean isListMovieCommand(String command) {
        return command.trim().equalsIgnoreCase(BibliotecaConstans.LIST_MOVIE_COMMAND);
    }

    public static boolean isCheckoutMovieCommand(String command) {
        String[] subCommands = command.split(" ");
        return subCommands.length > 1 && BibliotecaConstans.CHECKOUT_MOVIE_COMMAND.equalsIgnoreCase(subCommands[0]);
    }

    public static String resolveCheckoutMovie(String command) {
        return command.substring(BibliotecaConstans.CHECKOUT_MOVIE_COMMAND.length()).trim();
    }

    public static boolean isLoginCommand(String command) {
        String[] subCommands = command.split(" ");
        return subCommands.length == 7 && BibliotecaConstans.LOGIN.equalsIgnoreCase(subCommands[0]) && BibliotecaConstans.USER_NAME.equalsIgnoreCase(subCommands[1]) && BibliotecaConstans.PASSWORD.equalsIgnoreCase(subCommands[3]) && BibliotecaConstans.NUMBER.equalsIgnoreCase(subCommands[5]);
    }

    public static BibliotecaUser resolveLoginUser(String command) {
        String[] subCommands = command.split(" ");
        String username = subCommands[2];
        String password = subCommands[4];
        String number = subCommands[6];
        BibliotecaUser user = new BibliotecaUser();
        user.setUserName(username);
        user.setPassword(password);
        user.setNumber(number);
        user.setEmail("502089948@qq.com");
        user.setPhoneNumber("15520552070");
        return user;
    }

    public static boolean isInfoCommand(String command) {
        return  BibliotecaConstans.INFO_COMMAND.equalsIgnoreCase(command);
    }
}
